package org.yong.springbootcmd.util;


import org.yong.springbootcmd.exception.BusinessException;
import org.yong.springbootcmd.model.enu.ErrorCode;

public class BusinessAssert {

  public static <T> void validationLogin(T user) {
    throwCode(null == user, ErrorCode.INVALID_LOGIN_NAME_OR_PASSWORD);
  }

  public static void exist(boolean isThrow, String message) {
    throwCode(isThrow, ErrorCode.EXIST, message);
  }

  public static <T> void checkLogin(T user) {
    throwCode(null == user, ErrorCode.NOT_LOGIN);
  }

  public static void notExist(Object o, String message) {
    throwCode(null == o, ErrorCode.NOT_EXIST, message);
  }

  public static void notNull(Object o, String message) {
    throwCode(null == o, ErrorCode.NOT_NULL, message);
  }

  public static void illegalOperation(boolean isThrow, String message) {
    throwCode(isThrow, ErrorCode.ILLEGAL_OPERATION, message);
  }

  public static void throwCode(boolean isThrow, ErrorCode errorCode) {
    throwCode(isThrow, errorCode, null);
  }

  public static void throwCode(boolean isThrow, ErrorCode errorCode, String message) {
    if (isThrow) throw new BusinessException(errorCode, message);
  }
}
